home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / diskutil / lockkey.lzh / LOCKKEY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-16  |  16.0 KB  |  518 lines

  1. /**************************************************************************
  2. *                                LOCK & KEY                               *
  3. *                             by Jesse  Devine                            *
  4. *                       (C) 1988 Antic Publishing Inc.                    *
  5. *                                                                         *
  6. *      This program was written entirely with Lattice C around 6/87,      *
  7. *      and regularly re-written until 2/88.                               * 
  8. ***************************************************************************/
  9.  
  10. #define BYTE   char              /* signed 8 bit integer */
  11. #define UBYTE  unsigned char     /* unsigned 8 bit int   */
  12. #define WORD   short             /* signed 16 bit int    */
  13. #define UWORD  unsigned short    /* unsigned 16 bit int  */
  14. #define LONG   int               /* signed 32 bit int    */
  15. #define ULONG  unsigned long     /* unsigned 32 bit int  */
  16.  
  17. main()
  18. {
  19.    LONG   size;
  20.  
  21.    WORD   work_in[12], work_out[57];
  22.    WORD   handle,i,rc;
  23.    WORD   gr_1,gr_2,gr_3,gr_4;
  24.  
  25.    BYTE   folder[13];
  26.    BYTE   password[10];
  27.    BYTE   *buffer;
  28.  
  29. /** Do the usual housekeeping stuff **/
  30.  
  31.    appl_init();
  32.    handle=graf_handle(&gr_1,&gr_2,&gr_3,&gr_4);
  33.  
  34.    for(i=0; i<10; i++)
  35.       work_in[i] = 1;
  36.    work_in[10] = 2;
  37.    v_opnvwk(work_in, &handle, work_out);
  38.  
  39.    graf_mouse(0,1);
  40.  
  41.    vsf_interior(handle,4);
  42.    vsf_color(handle,1);
  43.    v_show_c(handle);
  44.  
  45.  
  46. /** This is where the meaty stuff begins **/
  47.  
  48.    retry:
  49.    buffer = (BYTE *)infile("lockkey.dat",&size);
  50.    if(buffer == 0){
  51.       rc = form_alert(1,"[1][|SORRY! LOCKKEY.DAT|could not be opened.][RETRY|CANCEL]");
  52.       if(rc == 1)
  53.          goto retry;
  54.       else
  55.          goto end;
  56.    }
  57.  
  58.    title:
  59.    rc = form_alert(1,"[0][          Lock & Key          |     Installation Program     |        by Jesse Devine       |(C)1988 Antic Publishing, Inc.][OK|CANCEL]");
  60.    if(rc == 2)
  61.       goto end;
  62.  
  63.    fldr:
  64.    rc = dialog("Please enter the name of","the folder you wish to make",
  65.                "a key for.","",folder,"________.___","FFFFFFFFFFF",
  66.                "OK","CANCEL",1);
  67.    if(rc == 2)
  68.       goto end;
  69.  
  70.    rc = dialog("Please enter the password you",
  71.                "wish to use to access the folder.","","",
  72.                password,"________","FFFFFFFF","OK","CANCEL",1);
  73.    if(rc == 2)
  74.       goto fldr;
  75.  
  76. /** Scramble password & folder, then insert in buffer **/
  77.  
  78.    for(i = 0 ; i != 11 ; i++)                /* Clear out previous folder   */
  79.       buffer[i + 0x2dc] = 0;                 /* 0x2dc: folder starts        */
  80.                                                                           
  81.    for(i = 0 ; i != 8 ; i++)                 /* Clear out previous password */
  82.       buffer[i + 0x2e8] = 0;                 /* 0x2e8: password starts      */
  83.  
  84.    for(i = 0;i != strlen(folder);i++)        /* Insert new scrambled folder */
  85.       buffer[0x2dc + i] = folder[i] - 1;
  86.  
  87.    for(i = 0; i != strlen(password);i++)     /* Insert scrambled password   */
  88.       buffer[0x2e8 + i] = password[i] - 1;
  89.  
  90.  
  91. /** Write the file back to disk **/
  92.  
  93.    again:
  94.    rc = form_alert(1,"[2][Which disk drive contains|the folder you wish to make|a key for?][  A  |  B  ]");
  95.    if(rc == 1)
  96.       gemdos(0x0e,0);                          /* Set current drive to A:   */
  97.    else
  98.       gemdos(0x0e,1);                          /* Set current drive to B:   */
  99.  
  100.    gemdos(0x3b,"\x5c");                        /* Set current dir to root   */
  101.  
  102.    rc = outfile("key.tos",buffer,size + 19);
  103.    if(rc == 0){
  104.       rc = form_alert(1,"[1][|Uh-Oh... I'm having trouble|writing a key to the disk.][RETRY|CANCEL]");
  105.       if(rc == 1)
  106.          goto again;
  107.       else
  108.          goto stop;
  109.    }
  110.    if(rc == -1)
  111.       goto stop;
  112.  
  113.    form_alert(1,"[1][|Installation Complete.][OK]");
  114.  
  115. /** Close the workstation. **/
  116.  
  117.    stop:
  118.    gemdos(0x49,(LONG)buffer);                  /* Release memory            */
  119.  
  120.    end:
  121.    v_clsvwk(handle);                           /* Close virtual workstation */
  122.    appl_exit();                                /* Release gem application   */
  123.  
  124.    _exit(0);                                   /* And exit                  */
  125.    return 0;
  126.  
  127. }
  128.  
  129. /***************************************************************************
  130. *                              D I A L O G                                 *
  131. *                                                                          *
  132. * dialog(str1,str2,str3,str4,text,template,valid,button1,button2,default); *
  133. *                                                                          *
  134. *       This function displays a dialog box with four lines of text, one   *
  135. *  GEM input line, and one or two buttons.                                 *
  136. ***************************************************************************/
  137.  
  138. LONG dialog(st1,st2,st3,st4,te_ptext,te_ptmplt,te_pvalid,but1,but2,def)
  139. BYTE *st1, *st2, *st3, *st4;
  140. BYTE *te_ptext, *te_ptmplt, *te_pvalid;
  141. BYTE *but1, *but2;
  142. LONG def;
  143. {
  144.  
  145.    LONG length,slen,blen;
  146.    WORD rc,i,cx,cy,cw,ch,line;
  147.  
  148.    struct{
  149.       char  *text;
  150.       char  *mask;
  151.       char  *valid;
  152.       WORD  font;
  153.       WORD  resvd1;
  154.       WORD  just;
  155.       WORD  color;
  156.       WORD  resvd2;
  157.       WORD  thick;
  158.       WORD  txtlen;
  159.       WORD  msklen;
  160.    }ted[1];
  161.  
  162.    struct{
  163.       WORD next;
  164.       WORD start;
  165.       WORD end;
  166.       WORD type;
  167.       WORD flags;
  168.       WORD status;
  169.       WORD thick;
  170.       WORD color;
  171.       WORD x;
  172.       WORD y;
  173.       WORD w;
  174.       WORD h;
  175.    }tree[8];
  176.  
  177. /*******************************************
  178. *    Get length of longest string          *
  179. *******************************************/
  180.  
  181.    length = strlen(st1);
  182.  
  183.    slen = strlen(st2);
  184.    if(slen > length)
  185.       length = slen;
  186.  
  187.    slen = strlen(st3);
  188.    if(slen > length)
  189.       length = slen;
  190.  
  191.    slen = strlen(st4);
  192.    if(slen > length)
  193.       length = slen;
  194.  
  195.    slen = strlen(te_ptmplt);
  196.    if(slen > length)
  197.       length = slen;
  198.  
  199. /*******************************************
  200. *       Get length of longest button       *
  201. *******************************************/
  202.  
  203.    blen = strlen(but1);
  204.  
  205.    if(strlen(but2) > blen)
  206.       blen = strlen(but2);
  207.  
  208. /*******************************************
  209. *         Create root object  #0           *
  210. *******************************************/
  211.    tree[0].next   = -1;
  212.    tree[0].start  = 1;
  213.    tree[0].end    = 7;
  214.    tree[0].type   = 20;
  215.    tree[0].flags  = 0;
  216.    tree[0].status = 16;
  217.    tree[0].thick  = 1;
  218.    tree[0].color  = 4592;
  219.    tree[0].x      = 0;
  220.    tree[0].y      = 0;
  221.    tree[0].w      = length + 4;
  222.    tree[0].h      = 0;
  223.  
  224.    line = 0;
  225.  
  226. /*******************************************
  227. *          Create first textline  #1       *
  228. *******************************************/
  229.  
  230.    if(st1[0] != 0)
  231.       line++;
  232.  
  233.    tree[1].next   = 2;
  234.    tree[1].start  = -1;
  235.    tree[1].end    = -1;
  236.    tree[1].type   = 28;
  237.    tree[1].flags  = 0;
  238.    tree[1].status = 0;
  239.    tree[1].thick  = ((LONG)st1) / 65536;
  240.    tree[1].color  = ((LONG)st1) % 65536;
  241.    tree[1].x      = 2;
  242.    tree[1].y      = line;
  243.    tree[1].w      = 0;
  244.    tree[1].h      = 1;
  245.  
  246. /*******************************************
  247. *       Create second textline  #2         *
  248. *******************************************/
  249.  
  250.    if(st2[0] != 0)
  251.       line++;
  252.  
  253.    tree[2].next   = 3;
  254.    tree[2].start  = -1;
  255.    tree[2].end    = -1;
  256.    tree[2].type   = 28;
  257.    tree[2].flags  = 0;
  258.    tree[2].status = 0;
  259.    tree[2].thick  = ((LONG)st2) / 65536;
  260.    tree[2].color  = ((LONG)st2) % 65536;
  261.    tree[2].x      = 2;
  262.    tree[2].y      = line;
  263.    tree[2].w      = 0;
  264.    tree[2].h      = 1;
  265.  
  266. /*******************************************
  267. *         Create third textline   #3       *
  268. *******************************************/
  269.  
  270.    if(st3[0] != 0)
  271.       line++;
  272.  
  273.    tree[3].next   = 4;
  274.    tree[3].start  = -1;
  275.    tree[3].end    = -1;
  276.    tree[3].type   = 28;
  277.    tree[3].flags  = 0;
  278.    tree[3].status = 0;
  279.    tree[3].thick  = ((LONG)st3) / 65536;
  280.    tree[3].color  = ((LONG)st3) % 65536;
  281.    tree[3].x      = 2;
  282.    tree[3].y      = line;
  283.    tree[3].w      = 0;
  284.    tree[3].h      = 1;
  285.  
  286. /*******************************************
  287. *        Create fourth textline   #4       *
  288. *******************************************/
  289.  
  290.    if(st4[0] != 0)
  291.       line++;
  292.  
  293.    tree[4].next   = 5;
  294.    tree[4].start  = -1;
  295.    tree[4].end    = -1;
  296.    tree[4].type   = 28;
  297.    tree[4].flags  = 0;
  298.    tree[4].status = 0;
  299.    tree[4].thick  = ((LONG)st4) / 65536;
  300.    tree[4].color  = ((LONG)st4) % 65536;
  301.    tree[4].x      = 2;
  302.    tree[4].y      = line;
  303.    tree[4].w      = 0;
  304.    tree[4].h      = 1;
  305.  
  306. /*******************************************
  307. *       Create editable textline  #5       *
  308. *******************************************/
  309.  
  310.    line++;
  311.    line++;
  312.  
  313.    tree[5].next   = 6;
  314.    tree[5].start  = -1;
  315.    tree[5].end    = -1;
  316.    tree[5].type   = 29;
  317.    tree[5].flags  = 8;
  318.    tree[5].status = 0;
  319.    tree[5].thick  = ((LONG)ted) / 65536;
  320.    tree[5].color  = ((LONG)ted) % 65536;
  321.    tree[5].x      = (tree[0].w / 2) - (strlen(te_ptmplt) / 2);
  322.    tree[5].y      = line;
  323.    tree[5].w      = strlen(te_ptmplt);
  324.    tree[5].h      = 1;
  325.  
  326. /*******************************************
  327. *         Create first button  #6          *
  328. *******************************************/
  329.  
  330.    line++;
  331.    line++;
  332.  
  333.    tree[6].next   = 7;
  334.    tree[6].start  = -1;
  335.    tree[6].end    = -1;
  336.    tree[6].type   = 26;
  337.    tree[6].flags  = 13;
  338.    tree[6].status = 0;
  339.    tree[6].thick  = ((LONG)but1) / 65536;
  340.    tree[6].color  = ((LONG)but1) % 65536;
  341.    tree[6].x      = 0;
  342.    tree[6].y      = line;
  343.    tree[6].w      = blen + 1;
  344.    tree[6].h      = 1;
  345.  
  346. /*******************************************
  347. *         Create second button  #7         *
  348. *******************************************/
  349.    tree[7].next   = 0;
  350.    tree[7].start  = -1;
  351.    tree[7].end    = -1;
  352.    tree[7].type   = 26;
  353.    tree[7].flags  = 0;
  354.    tree[7].status = 0;
  355.    tree[7].thick  = ((LONG)but2) / 65536;
  356.    tree[7].color  = ((LONG)but2) % 65536;
  357.    tree[7].x      = 0;
  358.    tree[7].y      = line;
  359.    tree[7].w      = blen + 1;
  360.    tree[7].h      = 1;
  361.  
  362. /*******************************************
  363. *          Adjust height of box            *
  364. *******************************************/
  365.  
  366.    tree[0].h = line + 2;
  367.  
  368. /*******************************************
  369. *            TEDINFO definitions           *
  370. *******************************************/
  371.  
  372.    ted[0].text   = te_ptext;
  373.    ted[0].mask   = te_ptmplt;
  374.    ted[0].valid  = te_pvalid;
  375.    ted[0].font   = 3;
  376.    ted[0].resvd1 = 6;
  377.    ted[0].just   = 0;
  378.    ted[0].color  = 4480;
  379.    ted[0].resvd2 = 0;
  380.    ted[0].thick  = 0;
  381.    ted[0].txtlen = ((WORD)strlen(te_pvalid) + 1);
  382.    ted[0].msklen = ((WORD)strlen(te_pvalid) + 1);
  383.  
  384. /*******************************************
  385. *        Convert object dimensions         *
  386. *******************************************/
  387.  
  388.    for(i = 0; i != 8;i++)
  389.       rsrc_obfix(tree,i);
  390.  
  391. /*******************************************
  392. *            Figure out buttons            *
  393. *******************************************/
  394.  
  395.    if(strcmp(but1,"") == 0)
  396.       return -1;
  397.  
  398.    if(strcmp(but2,"") == 0){
  399.       tree[6].x = (tree[0].w / 2) - (tree[6].w / 2);
  400.       tree[7].type = 28;
  401.    }
  402.    else{
  403.       tree[6].x = tree[0].x + 16;
  404.       tree[7].x = tree[0].x + tree[0].w - tree[7].w - 16;
  405.       tree[7].flags = 13;
  406.    }
  407.  
  408.    tree[5 + def].flags = tree[5 + def].flags + 2;
  409.  
  410. /************* Center dialog box ************/
  411.  
  412.    form_center(tree,&cx,&cy,&cw,&ch);
  413.    tree[0].x = cx;
  414.    tree[0].y = cy;
  415.  
  416. /*************** Draw it and do it ************/
  417.  
  418.  
  419.    form_dial(0,0,0,0,0,cx-4,cy-4,cw,ch);
  420.    form_dial(1,0,0,0,0,cx,cy,cw,ch);
  421.  
  422.    objc_draw(tree,0,1,0,0,638,198);             /* Draw object tree          */
  423.    rc = form_do(tree,5) - 5;
  424.  
  425.    form_dial(2,0,0,0,0,cx,cy,cw,ch);
  426.    form_dial(3,0,0,0,0,cx-4,cy-4,cw,ch);
  427.  
  428.    return (LONG)rc;
  429. }
  430.  
  431. /*****************************************************************************
  432. *                                I N F I L E                                 *
  433. *                                                                            *
  434. *  infile(filename,&size);                                                   *
  435. *                                                                            *
  436. *     This function inputs the given file, after having allocated sufficient *
  437. *  memory for it, and returns the address of the buffer where said file is   *
  438. *  located. Additionally, it returns the size of the file.                   *
  439. *****************************************************************************/
  440.  
  441. LONG infile(filename,size)
  442. BYTE *filename;
  443. LONG *size;
  444. {
  445.    LONG   rc;
  446.    WORD   f1;
  447.    BYTE   *buffer;
  448.    static UBYTE dta[44];
  449.  
  450.    gemdos(26,dta);                                /* Pass DTA value to sys  */
  451.    rc = gemdos(78,filename,7);                    /* Pass fname to system   */
  452.    if(rc < 0)                                     /* If file cannot be      */
  453.       goto abend;                                 /* Opened, goto end.      */
  454.  
  455.    *size = dta[27]*65536+dta[28]*256+dta[29];    /* Determine size of file */
  456.  
  457.    buffer = (BYTE *)gemdos(72,*size);             /* Request buffer space.  */
  458.    if(buffer < 0)                                 /* If not enough memory,  */
  459.       goto abend;                                 /* Goto abnormal end.     */
  460.  
  461.    f1 = gemdos(61,filename,0);                    /* Open file through GEM  */
  462.    if(f1 < 0)                                     /* If file cannot be      */
  463.       goto abend;                                 /* Goto end.              */
  464.  
  465.    rc = gemdos(63,f1,*size,(LONG)buffer);         /* Read entire file in    */
  466.    if(rc < 0)                                     /* If trouble reading,    */
  467.       goto abend;                                 /* goto end.              */
  468.  
  469.    gemdos(62,f1);                                 /* Close file through gem */
  470.  
  471.    return (LONG)buffer;                           /* Return buffer address  */
  472.  
  473.    abend:                                         /* Abnormal ending        */
  474.    return 0;                                      /* Return a zero          */
  475. }
  476.  
  477. /*****************************************************************************
  478. *                                 O U T F I L E                              *
  479. *                                                                            *
  480. *  outfile(filename,buffer,size)                                             *
  481. *                                                                            *
  482. *     This function outputs the contents of the given buffer to the file     *
  483. *  name given.                                                               *
  484. *****************************************************************************/
  485.  
  486. LONG outfile(filename,buffer,size)
  487. BYTE *filename,*buffer;
  488. LONG size;
  489. {
  490.    LONG   rc;
  491.    WORD   f1;
  492.  
  493.    f1 = gemdos(61,filename,0);                    /* Check if file exists   */
  494.    if(f1 > 0){
  495.       rc = form_alert(1,"[2][KEY.TOS already exists|on this disk. Write|over existing file?][OK|CANCEL]");
  496.       if(rc == 2)
  497.          return -1;                               /* Indicate immediate end */
  498.    }
  499.  
  500.    f1 = gemdos(60,filename,0);                    /* Open file through GEM  */
  501.    if(f1 < 0)                                     /* If file cannot be      */
  502.       goto stop;                                  /* Goto stop.             */
  503.  
  504.    rc = gemdos(64,f1,size,buffer);                /* Write entire file out  */
  505.    if(rc < 0)                                     /* If trouble writing,    */
  506.       goto stop;                                  /* try again.             */
  507.  
  508.    gemdos(62,f1);                                 /* Close file through gem */
  509.  
  510.    return 1;                                      /* End function w/ rc = 1 */
  511.  
  512.    stop:                                          /* Abnormal ending        */
  513.    return 0;                                      /* Return a 0             */
  514.  
  515. }
  516.  
  517.  
  518.